package org.domain.sigerec.session;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;

import org.domain.sigerec.entity.Cabine;
import org.domain.sigerec.entity.Navio;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;

@Name("cabineList")
public class CabineList extends EntityQuery<Cabine>{
    
	private static final long serialVersionUID = 2807882661834593259L;
	
	private static final String[] RESTRICTIONS = { "lower(cabine.numero) like concat(lower(#{cabineList.cabine.numero}),'%') ",};
	
	@Override
    public String getEjbql() 
    { 
        return "select cabine from Cabine cabine";
    }
	
	private Cabine cabine = new Cabine();
	
	private Navio navio = new Navio();
	
	private boolean pesquisou;

	public String pesquisar() {
		pesquisou = true;
		return null;
	}
	
	public List<Cabine> getCabines() {
		if (pesquisou || getFirstResult()!=null) {
			return getResultList();
		}
		return null;
	}
	
	@Override
	public Integer getMaxResults() {
		return 25;
	}

	public Cabine getCabine() {
		return cabine;
	}
	
	public Navio getNavio() {
		return navio;
	}
	
	@Override
	public List<String> getRestrictions() {
		return Arrays.asList(RESTRICTIONS);
	}
	
}
